import React from "react";
import { Button } from "@tarojs/components";
import { AuthButtonProps } from "../../../types/components/auth-button";
/**
 * AuthButton 授权Button
 */
const AuthButton: React.FC<AuthButtonProps> = ({
  openType,
  onCallBack,
  ...props
}) => {
  /**
   * 点击授权登录
   * @param e
   */
  const onGetUserInfo = function(e) {
    onCallBack && onCallBack(e);
  };

  /**
   * 点击授权手机号
   * @param e
   */
  const onGetPhoneNumber = e => {
    onCallBack && onCallBack(e);
  };

  let eventProps = {};
  switch (openType) {
    case "getUserInfo":
      eventProps = {
        onGetUserInfo
      };
      break;
    case "getPhoneNumber":
      eventProps = {
        onGetPhoneNumber
      };
      break;
  }

  return (
    <Button className="btn btn-mid btn-primary" {...props} {...eventProps}>
      {props.children}
    </Button>
  );
};
export default AuthButton;
